//
//  LoginViewController.m
//  Qya
//
//  Created by maxwellpang on 12-9-7.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "LoginViewController.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        shang = NO;
        remOn = NO;
        autoON = NO;

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    inputName.delegate = self;
    inputKeywd.delegate = self;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

-(IBAction)login:(id)sender
{
    if (![[inputName text] isEqualToString:@"10086"]|| ![[inputKeywd text] isEqualToString:@"10086"]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"登陆失败" message:@"用户名或密码错误\n提示:10086" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        
        [alert show];
        return;
    }
    [inputName resignFirstResponder];
    [inputKeywd resignFirstResponder];
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationFinished)];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:0.1];
//    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view.superview cache:NO];    
//    [self.view removeFromSuperview];
    

     CGPoint center = wholeView.center;
     center.y = center.y - 480;
     wholeView.center = center;
    
    [UIView commitAnimations];
}

- (void)animationFinished
{
    [self.view removeFromSuperview];
} 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    if (shang == false) {
        [UIView beginAnimations:@"turnDark" context:nil];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:0.3];
        
        CGPoint itCenter = [loginToolView center];
        itCenter.y -= 150; 
        loginToolView.center = itCenter;
        
        [UIView commitAnimations];
        shang = YES;
    }

    return YES;
}

-(IBAction)rememberIt:(id)sender
{
    if (remOn == NO) {
        [btRem setImage:[UIImage imageNamed:@"jizhumimaxuanzhong"] forState:UIControlStateNormal];
        remOn = YES;
    }
    else {
        [btRem setImage:[UIImage imageNamed:@"jizhumimaweixuanzhong"] forState:UIControlStateNormal];
        remOn = NO;
    }
}
-(IBAction)autoLogin:(id)sender
{
    if (autoON == NO) {
        [btAuto setImage:[UIImage imageNamed:@"zidongdengluxuanzhong"] forState:UIControlStateNormal];
        autoON = YES;
    }
    else {
        [btAuto setImage:[UIImage imageNamed:@"zidongdengluweixuanzhong"] forState:UIControlStateNormal];
        autoON = NO;
    }
}


@end
